package com.choosefine.it.project.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.choosefine.it.base.BaseController;
import com.choosefine.it.common.def.ResultCode;
import com.choosefine.it.common.model.CustomRestTemplate;
import com.choosefine.it.common.utils.StringUtils;
import com.choosefine.it.common.utils.URLHandlerUtils;
import com.choosefine.it.project.model.dto.MaterialFacilitiesDTO;
import com.choosefine.it.project.model.dto.ProjectTeamCapitalDetail;
import com.choosefine.it.project.model.dto.SelectProjectCondition;
import com.choosefine.it.project.model.dto.SelectProjectTeam;
import com.choosefine.it.project.model.vo.ProjectTeamCapitalDetailVO;
import com.choosefine.it.project.model.vo.ProjectTeamCapitalVO;
import com.choosefine.it.project.model.vo.ProjectTeamTotalVO;
import com.choosefine.it.project.service.ProjectCapitalService;
import com.github.pagehelper.Page;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

/**
 * @author yeliang
 * @time 2016年12月8日 下午6:03:20
 * @describe 工程项目查询
 */
@RestController
@Api(value="控制台——项目管理-项目的资金统计(工程项目查询)",description="叶亮|毛俊")
@RequestMapping("")
public class ProjectCapitalController extends BaseController {

	@Value("#{yaml.get('shopping.getShopCapitalListByType')}")
	String getShopCapitalListByTypeURL=null;
	@Value("#{yaml.get('shopping.getShopCapitalListDetail')}")
	String getShopCapitalListDetailURL=null;
	
	@Autowired
	ProjectCapitalService projectCapitalService;
	
	@Autowired
	CustomRestTemplate restTemplate;

	/**
	 * 获取项目资金统计接口
	 * @param selectProjectCondition
	 * @return
	 */
	@ApiOperation(value = "项目资金查询",response = ProjectTeamCapitalVO.class)
	@RequestMapping(value="KZT0590/getProjectCapital",method=RequestMethod.POST)
	public String getProjectCapital(@RequestBody SelectProjectCondition selectProjectCondition){
		Page<ProjectTeamCapitalVO> pageList = projectCapitalService.getProjectCapital(selectProjectCondition);
		return responseSuccess(pageList.toPageInfo(), ResultCode.SUCCESS,ResultCode.MSG_QUERY_SUCCESS);
	}

	/**
	 *工程项目资金班组资金管理
	 * @param selectProjectTeam
	 * @return
	 */
	@ApiOperation(value = "工程项目资金班组资金管理",response = ProjectTeamTotalVO.class)
	@RequestMapping(value="KZT0600/getProjectTeamCapital",method=RequestMethod.POST)
	public String getProjectTeamCapital(@RequestBody SelectProjectTeam selectProjectTeam){

		if(StringUtils.isEmpty(selectProjectTeam.getProjectCode())){
			return  responseFail(ResultCode.MSG_PARAMS_NULL);
		}
		Page<ProjectTeamTotalVO> pageList = projectCapitalService.getProjectTeamCapital(selectProjectTeam);
		return responseSuccess(pageList.toPageInfo(), ResultCode.SUCCESS,ResultCode.MSG_QUERY_SUCCESS);
	}

	/**
	 * 工程项目资金统计班组资金管理转账明细查询
	 * @param projectTeamCapitalDetail
	 * @return
	 */
	@ApiOperation(value = "工程项目资金统计班组资金管理转账明细查询",response = ProjectTeamCapitalDetailVO.class)
	@RequestMapping(value="KZT0610/getProjectTeamCapitalDetail",method=RequestMethod.POST)
	public String getProjectTeamCapitalDetail(@RequestBody ProjectTeamCapitalDetail projectTeamCapitalDetail){

		if(projectTeamCapitalDetail.getTeamId() == null){
			return  responseFail(ResultCode.MSG_PARAMS_NULL);
		}
		Page<ProjectTeamCapitalDetailVO> pageList = projectCapitalService.getProjectTeamCapitalDetail(projectTeamCapitalDetail);
		return responseSuccess(pageList.toPageInfo(), ResultCode.SUCCESS,ResultCode.MSG_QUERY_SUCCESS);

	}
	
	/**
	 * 获取项目材料设备设施资金统计
	 * @param materialFacilitiesDTO
	 * @return
     */
	@ApiOperation(value="项目资金管理-材料设备设施资金统计",response = String.class)

	@RequestMapping(value="KZT0530/getShopCapitalListByType",method=RequestMethod.POST)
	public String getShopCapitalListByType(@RequestBody MaterialFacilitiesDTO materialFacilitiesDTO){

		StringBuffer url = URLHandlerUtils.getUrlBuffer(shoppingURL,  getShopCapitalListByTypeURL);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("pageNum",materialFacilitiesDTO.getPageNum());
	    map.put("pageSize",materialFacilitiesDTO.getPageSize());
		map.put("projectCode",materialFacilitiesDTO.getProjectCode());
		map.put("supplierUserCode",materialFacilitiesDTO.getSupplierUserCode());
		map.put("supplierUserName",materialFacilitiesDTO.getSupplierUserName());
		map.put("companyLegal",materialFacilitiesDTO.getCompanyLegal());
		map.put("merchandiseType",materialFacilitiesDTO.getType());
		map.put("operationDate",materialFacilitiesDTO.getMonth());
		map.put("teamId",materialFacilitiesDTO.getTeamId());
		String str=URLHandlerUtils.urlFormat(url,map);
		ResponseEntity<String> exchange = restTemplate.exchange(str,HttpMethod.GET,null, String.class);
		String body = exchange.getBody().toString();
		return body;
	}

	/**
	 *项目资金管理-材料设备设施资金明细
	 * @param projectCode
	 * @param merchandiseType
	 * @param shopId
	 * @param pageNum
	 * @param pageSize
     * @return
     */
	@ApiOperation(value="项目资金管理-材料设备设施资金明细",response = String.class)
	@ApiImplicitParams({
			@ApiImplicitParam(name="merchandiseType",value="类型",dataType="int",required = true,paramType =  "query"),
			@ApiImplicitParam(name="shopId",value="商城店铺id",dataType="long",required = true,paramType =  "query"),
			@ApiImplicitParam(name="projectCode",value="项目编码", dataType = "String",required = false, paramType = "query"),
			@ApiImplicitParam(name="pageNum",value="起始页",dataType="int",required = true,paramType =  "query"),
			@ApiImplicitParam(name="pageSize",value="页面条数",dataType="int",required = true,paramType =  "query"),
			@ApiImplicitParam(name="teamId",value="班组id",dataType="int",required = false,paramType =  "query")
	})
	@RequestMapping(value="KZT0540/getShopCapitalListDetail",method=RequestMethod.GET)
	public String getShopCapitalListDetail(String projectCode,Integer merchandiseType,Long shopId,Integer pageNum,Integer pageSize,Integer teamId){
		StringBuffer url = URLHandlerUtils.getUrlBuffer(shoppingURL,  getShopCapitalListDetailURL);
		Map<String,Object> map=new HashMap<String,Object>();
		map.put("pageNum",pageNum);
		map.put("pageSize",pageSize);
		map.put("projectCode",projectCode);
		map.put("teamId",teamId);
		map.put("shopId",shopId);
		String str=URLHandlerUtils.urlFormat(url,map);
		ResponseEntity<String> exchange = restTemplate.exchange(str,HttpMethod.GET,null, String.class);
		String body = exchange.getBody().toString();
		return body;
	}
}
